import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate'
import type { App } from 'vue'

const store = createPinia()

store.use(
  createPersistedState({
    storage: sessionStorage,
    key(storeKey) {
      return `__persisted__${storeKey}`
    },
    auto: false
  })
)

const setupStore = (app: App) => {
  app.use(store)
}

export { store, setupStore }
